//# sourceURL=http://uMapApp/UI/IconMenu/IconMenuItem
define([
    "mhjs/mhjs",
    "./IconMenuSlide"
], function (
    mhjs,
    IconMenuSlide
) {

    function IconMenuItem(option) {

        var _this = this;

        _this.button = $("<div class='iconMenuButton'><img/></div>");

        _this.isActive = false;
        _this.isEnable = true;

        mhjs.Div.call(_this, option);
        _this.addClass("iconMenuItem");

        _this.hover(function () {
            if (_this._slide) {
                _this.toggle();
            }
        }, function () {
            if (_this._slide) {
                _this.toggle();
            }
        });

        _this.append(_this.button);

        if (option.slide) {
            _this.slide = option.slide;
        } else {
            _this.onActive = option.onActive;
            _this.onInactive = option.onInactive;

            if (_this.onActive || _this.onInactive) {
                _this.dom.click(function () {
                    if (_this.isEnable) {
                        _this.toggleActive();
                    }
                });
            }

        }

        if (option.onInit) {
            option.onInit(_this);
        }


    }

    var _class = IconMenuItem;

    mhjs.Inherit(_class, mhjs.Div);

    Object.defineProperties(_class.prototype, {
        "icon"        : {
            set: function (icon) {
                var _this = this;
                _this._icon = icon;
                _this.button.find("img").attr("src", icon);
            },
            get: function () {
                return this._icon;
            }
        },
        "title"       : {
            set: function (title) {
                var _this = this;
                _this._title = title;
                _this.button.attr("title", title);
            },
            get: function () {
                return this._title;
            }
        },
        "slide"       : {
            set: function (slide) {
                var _this = this;
                if (slide) {
                    _this.enable();
                    _this._slide = new IconMenuSlide(slide);
                    _this._slide.parent = _this;
                    _this.dom.append(_this._slide.dom);
                } else {
                    _this.disable();
                }


            },
            get: function () {
                return this._slide;
            }
        },
        "open"        : {
            value: function () {
                this._slide.dom.slideDown("fast");
            }
        },
        "close"       : {
            value: function () {
                this._slide.dom.slideUp("fast");
            }
        },
        "toggle"      : {
            value: function () {
                this._slide.dom.slideToggle("fast");
            }
        },
        "active"      : {
            value: function () {

                if (!this.isActive) {
                    this._onActive && this._onActive(this);
                }
                this.dom.addClass("active");
                this.isActive = true;
            }
        },
        "onActive"    : {
            set: function (fun) {
                var _this = this;

                if (fun) {
                    _this._onActive = fun;
                    _this.enable();
                } else {
                    _this.disable();
                }

            },
            get: function () {
                return this._onActive;
            }
        },
        "inactive"    : {
            value: function () {
                if (this.isActive) {
                    this._onInactive && this._onInactive(this);
                }

                this.dom.removeClass("active");
                this.isActive = false;
            }
        },
        "onInactive"  : {
            set: function (fun) {
                var _this = this;
                _this._onInactive = fun;
            },
            get: function () {
                return this._onInactive;
            }
        },
        "toggleActive": {
            value: function () {
                if (this.isActive) {
                    this.inactive();
                } else {
                    this.active();
                }

            }
        },
        "checkActive" : {
            value: function () {

                if (this._slide.dom.find(".active").length > 0) {
                    this.active();
                } else {
                    this.inactive();
                }

            }
        },
        "enable"      : {
            value: function () {
                if (!this.isEnable) {
                    this.dom.removeClass("disable");
                    this.isEnable = true;
                }
            }
        },
        "disable"     : {
            value: function () {
                if (this.isEnable) {
                    this.dom.addClass("disable");
                    this.isEnable = false;
                }
            }
        },
        "toggleEnable": {
            value: function () {
                if (this.isEnable) {
                    this.disable();
                } else {
                    this.enable();
                }

            }
        }
    });

    return _class;


});